package units

import (
	"math/rand"
	"regexp"
	"time"
)

func CheckError(err error) {
	if err != nil {
		panic(err)
	}
}

func RandChar(n int) string {
	chars := []byte("0123456789abcdefghijklmnopqrstuvwxyz")
	res := make([]byte, n)
	rand.Seed(time.Now().Unix())
	for i, _ := range res {
		res[i] = chars[rand.Intn(len(chars))]
	}
	return string(res)
}

func CheckTelephone(telephone string) bool {
	if m, _ := regexp.MatchString(`^(1[3-9]\d\d{8})$`, telephone); !m {
		return false
	}
	return true
}

type UserData struct {
	AccessToken string `json:"access_token"`
	//	ExpiresIn    int    `json:"expires_in"`
	//	RefreshToken string `json:"refresh_toke1n"`
	Openid string `json:"openid"`
	//	Scope        string `json:"scope"`
	Unionid    string `json:"unionid"`
	Headimgurl string `json:"headimgurl"`
	Nickname   string `json:"nickname"`
}
